def trim(s):
	i = len(s)
	# 去除左边空格
	while i > 0:
		if s[0] == ' ':
			s = s[1:]
			i -= 1
		else:
			break
	i = len(s)
	# 去除右边空格
	while i > 0:
		if s[-1] == ' ':
			s = s[:-1]
			i -= 1
		else:
			break
	return s

# 测试
if trim('hello  ') != 'hello':
	print('测试失败!')
elif trim('  hello') != 'hello':
	print('测试失败!')
elif trim('  hello  ') != 'hello':
	print('测试失败!')
elif trim('') != '':
	print('测试失败!')
elif trim('   ') != '':
	print('测试失败!')
else:
	print('测试成功!')